﻿using System;
using System.IO;
using System.Windows.Forms;
using CommonCodeManagers.Model;
using CommonCodeManagers.plugin;
using Newtonsoft.Json;

namespace CommonCodeManagers
{
    public partial class SetGitAccount : Form
    {
        public WindowForm CodeManager { get; set; }
        public SetGitAccount()
        {
            InitializeComponent();
            
        }

        private void btnSetToAppConfig_Click(object sender, EventArgs e)
        {
            var jsonStr = JsonConvert.SerializeObject(new GitAccount()
            {
                Name = txtName.Text,
                Email = txtEmail.Text,
                UserName = txtEmail.Text,
                Password = txtPassWord.Text,
                Reposity = txtReposityUrl.Text
            });
            AppConfig.SetConfig("GitAccount", DESEncrypt.Encrypt(jsonStr));
            GitHandler.CloneRepository(jsonStr, Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "gitPath"));
            MessageBox.Show("初始化完成，请重新打开");
            Application.Exit();
        }

        private static void OpenNewCodeWindow()
        {
            
        }

        private void SetGitAccount_FormClosing(object sender, FormClosingEventArgs e)
        {
            
        }
    }
}
